package com.ruoyi.project.infoprojecttargetindex.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.project.infoprojecttargetindex.domain.InfoProjectTargetIndex;
import com.ruoyi.project.infoprojecttargetindex.service.IInfoProjectTargetIndexService;
import com.ruoyi.project.infoprojecttargetindex.vo.InfoProjectTargetIndexVo;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 项目目标填报—中的指标Controller
 *
 * @author ruoyi
 * @date 2022-02-08
 */
@RestController
@RequestMapping("/infoProjectTargetIndex/infoProjectTargetIndex")
public class InfoProjectTargetIndexController extends BaseController {
    @Autowired
    private IInfoProjectTargetIndexService infoProjectTargetIndexService;

    /**
     * 查询项目目标填报—中的指标列表
     */
    @PreAuthorize("@ss.hasPermi('infoProjectTargetIndex:infoProjectTargetIndex:list')")
    @GetMapping("/list")
    public TableDataInfo list(InfoProjectTargetIndex infoProjectTargetIndex) {
        startPage();
        List<InfoProjectTargetIndex> list = infoProjectTargetIndexService.selectInfoProjectTargetIndexList(infoProjectTargetIndex);
        return getDataTable(list);
    }

    /**
     * 导出项目目标填报—中的指标列表
     */
    @PreAuthorize("@ss.hasPermi('infoProjectTargetIndex:infoProjectTargetIndex:export')")
    @Log(title = "项目目标填报—中的指标", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, InfoProjectTargetIndex infoProjectTargetIndex) {
        List<InfoProjectTargetIndex> list = infoProjectTargetIndexService.selectInfoProjectTargetIndexList(infoProjectTargetIndex);
        ExcelUtil<InfoProjectTargetIndex> util = new ExcelUtil<InfoProjectTargetIndex>(InfoProjectTargetIndex.class);
        util.exportExcel(response, list, "项目目标填报—中的指标数据");
    }

    /**
     * 获取项目目标填报—中的指标详细信息
     */
//    @PreAuthorize("@ss.hasPermi('infoProjectTargetIndex:infoProjectTargetIndex:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(infoProjectTargetIndexService.selectInfoProjectTargetIndexById(id));
    }

    /**
     * 新增项目目标填报—中的指标
     */
//    @PreAuthorize("@ss.hasPermi('infoProjectTargetIndex:infoProjectTargetIndex:add')")
    @Log(title = "项目目标填报—中的指标", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody InfoProjectTargetIndex infoProjectTargetIndex) {
        return toAjax(infoProjectTargetIndexService.insertInfoProjectTargetIndex(infoProjectTargetIndex));
    }

    /**
     * 修改项目目标填报—中的指标
     */
//    @PreAuthorize("@ss.hasPermi('infoProjectTargetIndex:infoProjectTargetIndex:edit')")
    @Log(title = "项目目标填报—中的指标", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody InfoProjectTargetIndex infoProjectTargetIndex) {
        return toAjax(infoProjectTargetIndexService.updateInfoProjectTargetIndex(infoProjectTargetIndex));
    }

    /**
     * 删除项目目标填报—中的指标
     */
//    @PreAuthorize("@ss.hasPermi('infoProjectTargetIndex:infoProjectTargetIndex:remove')")
    @Log(title = "项目目标填报—中的指标", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(infoProjectTargetIndexService.deleteInfoProjectTargetIndexByIds(ids));
    }

    /**
     * 不分页获取
     *
     * @param projectId
     * @return
     */
    @RequestMapping(value = "/noPageList", method = RequestMethod.GET)
    public AjaxResult noPageList(@RequestParam("projectId") Long projectId) {
        InfoProjectTargetIndex infoProjectTargetIndex = new InfoProjectTargetIndex();
        infoProjectTargetIndex.setProjectId(projectId);
        List<InfoProjectTargetIndex> infoProjectIndices = infoProjectTargetIndexService.selectInfoProjectTargetIndexList(infoProjectTargetIndex);
        return AjaxResult.success(infoProjectIndices);
    }

    /**
     * 批量 插入项目指标
     *
     * @param projectIndexVo
     * @return
     */
    @RequestMapping(value = "/batchInsertProjectIndex", method = RequestMethod.POST)
    public AjaxResult batchInsertProjectIndex(@RequestBody InfoProjectTargetIndexVo projectIndexVo) {
        int i = infoProjectTargetIndexService.batchInsertProjectTargetIndex(projectIndexVo);
        return toAjax(i);
    }
}
